<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="添加地址"
        left-arrow
        @click-left="$router.back()"
      >
      </van-nav-bar>
    </header>
    <div class="content">
      <van-address-edit
        :area-list="areaList"
        show-set-default
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        save-button-text = "保存并且使用该地址"
      />
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { NavBar, AddressEdit } from 'vant'
// import { areaList } from '@vant/area-data'
import { areaList } from '@/utils/area.js'
import { updateOrderAddress } from '@/api/order'
import { addAddress } from '@/api/address'
import { getStorage } from '../../utils/storage'
Vue.use(NavBar)
Vue.use(AddressEdit)
export default {
  data () {
    return {
      areaList: areaList
    }
  },
  methods: {
    onSave (content) {
      console.log(content)
      content.userid = getStorage('userid')
      content.time = this.$route.params.time
      // 先添加数据，然后再更新数据
      addAddress(content).then(res1 => {
        updateOrderAddress(content).then(res => {
          // 返回上两页
          this.$router.go(-2)
        })
      })
    }
  }
}
</script>
